import axios from 'axios'
import { WorkTicketModel } from './work-ticket-model'
import { BizConfigUtils } from '@/common/biz-config-utils'

export class WorkTicketApi {
  private static serverAddress = `${BizConfigUtils.getGlobalConfig().serveAddress}/workticket`
  // private static serverAddress = 'http://10.254.193.221:8080/workticket'
  // private static serverAddress = '/workticket'
  public static save (data:WorkTicketModel):Promise<any> {
    return axios.post(this.serverAddress, data)
  }

  public static update (data:WorkTicketModel):Promise<any> {
    return axios.put(this.serverAddress, data)
  }

  public static deleteWorkTicket (id:string):Promise<any> {
    return axios.delete(this.serverAddress + '/' + id)
  }

  public static getWorkTicketById (id:string):Promise<any> {
    return axios.get(this.serverAddress + '/' + id)
  }

  public static exportWord ():string {
    return this.serverAddress + '/word/download'
  }

  public static query (pageIndex:number, pageSize:number, workTicketCode = null, username = null):Promise<any> {
    const loginUser = BizConfigUtils.getLoginUser()
    const teamId = loginUser.teamId
    const url = this.serverAddress + '/page?pageIndex=' + pageIndex + '&pageSize=' + pageSize + '&teamId=' + teamId + (!workTicketCode ? '' : '&workTicketCode=' + workTicketCode)
    return axios.get(url)
  }

  public static getWorkTicketyMaxId ():Promise<any> {
    const loginUser = BizConfigUtils.getLoginUser()
    const teamId = loginUser.teamId
    const url = this.serverAddress + '/max/id/' + teamId
    return axios.get(url)
  }
}
